<?php


class b2c_ctl_wap_index extends b2c_ctl_wap_common{  

    function __construct(&$app){
        parent::__construct($app);
      
        $shopname = app::get('wap')->getConf('wap.name');
        if(isset($shopname)){
            $this->title = app::get('b2c')->_('金邻速购').'_'.$shopname;
            $this->keywords = app::get('b2c')->_('金邻速购').'_'.$shopname;
            $this->description = app::get('b2c')->_('金邻速购').'_'.$shopname;
        }
        $this->pagesize = 10;
        $this->action = $this->_request->get_act_name();
        if(!$this->action) $this->action = 'index';
        $this->pagedata['res_url'] = $this->app->res_url;
        /** end **/
    }
    public function index(){
        $this->title =$this->shopname ? $this->title : "金邻速购";
        $this->keywords = $this->shopname? $this->keywords : "金邻速购";
        $this->description = $this->shopname ?$this->description :  "金邻速购";
        $input['method'] = array("file"=>"mobileapi_rpc_indexad","action"=>"get_ad");
        $input['data'] = array('app_ad_key'=>'1');
        $ad = $this->getApi($input);
        $input['method'] = array("file"=>"mobileapi_rpc_indexad","action"=>"get_ad");
        $input['data'] = array('app_ad_key'=>'2');
        $text_ad = $this->getApi($input);
        foreach($ad as $k=>$val){
            switch($val['url_type']){
                case "virtual_cat":
                    
                    break;
                case "goods":
                    break;
                case "article":
                    break;
                case "cat":
                    break;
            }
            
        }
        
        $input['method'] = array("file"=>"mobileapi_rpc_goods","action"=>"get_all_list");
        $input['data'] = array('son_object'=>'json','page_no'=>1,'page_size'=>10,'orderby'=>'uptime desc');
        $goodslist = $this->getApi($input);
        $goodslist = json_decode($goodslist['data']['items'],true);
        $this->pagedata['ad'] = $ad;
        $this->pagedata['text_ad'] = $text_ad['data'];
        $this->pagedata['goodslist'] = $goodslist['item'];
        $this->page('wap/index.html');
    }
    function cat(){
        $cats = app::get("b2c")->model("goods_cat")->getList();
        $catlist = array();
        foreach($cats as $k=>$cat ){
            if($cat['parent_id'] == 0){
                $catlist[$cat['cat_id']]['cat_id'] = $cat['cat_id'];
                $catlist[$cat['cat_id']]['cat_name'] = $cat['cat_name'];
                $catlist[$cat['cat_id']]['p_order'] = $cat['p_order'];
                $catlist[$cat['cat_id']]['child_count'] = $cat['child_count'];
                $catlist[$cat['cat_id']]['picture'] = $cat['picture'];
                $catlist[$cat['cat_id']]['picture2'] = $cat['picture2'];
            }else{
                $catlist[$cat['parent_id']]['child'][$cat['cat_id']]['cat_id'] = $cat['cat_id'];
                $catlist[$cat['parent_id']]['child'][$cat['cat_id']]['cat_name'] = $cat['cat_name'];
                $catlist[$cat['parent_id']]['child'][$cat['cat_id']]['p_order'] = $cat['p_order'];
                $catlist[$cat['parent_id']]['child'][$cat['cat_id']]['child_count'] = $cat['child_count'];
                $catlist[$cat['parent_id']]['child'][$cat['cat_id']]['picture'] = $cat['picture'];
            }
        }
        $ischeck = reset($catlist);
        $this->pagedata['catlist'] = $catlist;
        $this->pagedata['ischeck'] = $ischeck['cat_id'];
        $this->page('wap/cat.html');
        
    }
    function newgoods(){
        $cat_id = $_GET['cat_id'] ? $_GET['cat_id'] : 0;
        $input['method'] = array("file"=>"mobileapi_rpc_salesgoods","action"=>"sales_list");
        $input['data'] = array('son_object'=>'json','rule_id'=>1,'cat_id'=>$cat_id);
        $goodslist = $this->getApi($input);
        $this->pagedata['goodslist'] = $goodslist['data'][0]['goods'];
        $this->page('wap/newgoods.html');
        
    }
    function fancygoods(){
        $cat_id = $_GET['cat_id'] ? $_GET['cat_id'] : 0;
        $input['method'] = array("file"=>"mobileapi_rpc_salesgoods","action"=>"sales_list");
        $input['data'] = array('son_object'=>'json','rule_id'=>1,'cat_id'=>$cat_id);
        $goodslist = $this->getApi($input);
        $goodslist = json_decode($goodslist['data']['items'],true);
        $this->pagedata['goodslist'] = $goodslist['item'];
        $this->pagedata['act'] = "fancy";
        $this->pagedata['cat_id'] = $cat_id;
        $this->page('wap/catgoods.html');
    }
    function buygoods(){
        $cat_id = $_GET['cat_id'] ? $_GET['cat_id'] : 0;
        $input['method'] = array("file"=>"mobileapi_rpc_goods","action"=>"get_all_list");
        $input['data'] = array('son_object'=>'json','orderby'=>"buy_count desc",'cat_id'=>$cat_id);
        $goodslist = $this->getApi($input);
        $goodslist = json_decode($goodslist['data']['items'],true);
        $this->pagedata['goodslist'] = $goodslist['item'];
        $this->pagedata['act'] = "buy";
        $this->pagedata['cat_id'] = $cat_id;
        $this->page('wap/catgoods.html');
    }
    function goodsnew(){
        $cat_id = $_GET['cat_id'] ? $_GET['cat_id'] : 0;
        $input['method'] = array("file"=>"mobileapi_rpc_goods","action"=>"get_all_list");
        $input['data'] = array('son_object'=>'json','orderby'=>"uptime desc",'cat_id'=>$cat_id);
        $goodslist = $this->getApi($input);
        $goodslist = json_decode($goodslist['data']['items'],true);
        $this->pagedata['goodslist'] = $goodslist['item'];
        $this->pagedata['act'] = "new";
        $this->pagedata['cat_id'] = $cat_id;
        $this->page('wap/catgoods.html');
    }
    function pricegoods(){
        $cat_id = $_GET['cat_id'] ? $_GET['cat_id'] : 0;
        $input['method'] = array("file"=>"mobileapi_rpc_goods","action"=>"get_all_list");
        $input['data'] = array('son_object'=>'json','orderby'=>"price asc",'cat_id'=>$cat_id);
        $goodslist = $this->getApi($input);
        $goodslist = json_decode($goodslist['data']['items'],true);
        $this->pagedata['goodslist'] = $goodslist['item'];
        $this->pagedata['act'] = "price";
        $this->pagedata['cat_id'] = $cat_id;
        $this->page('wap/catgoods.html');
    }

}
